package com.example.demo2.test.pong;

import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import okhttp3.WebSocket;

@Slf4j
public class HuoBiPong implements Runnable {

	private static WebSocket webSocket;
	@Override
	public  void run(){
		while(true) {
			try {
				Thread.sleep(5000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			JSONObject jsonObject = new JSONObject();
			jsonObject.put("pong",System.currentTimeMillis());
			boolean b = webSocket.send(jsonObject.toJSONString());
			//检查连接是否正常
			if(!b){
				log.info("---------------huobi--pong异常");
			}
		}
	}
	public HuoBiPong(WebSocket webSocket){
		this.webSocket = webSocket;
	}
}